﻿Imports System.Net
Imports System.IO
Imports System.ComponentModel
Imports System.Threading
Imports System.Drawing
Imports pdflib
Imports System.Text.RegularExpressions
Public Class F_Main
    Private _saveDir As String
    Private Const _mbSize As Integer = 1048576
    Private _urlViewed As Dictionary(Of String, clsLink)
    Private _pdfSaved As Dictionary(Of String, clsLink)
    Private _dataUsage As Long
    Private _maxLevel As Integer
    Private _testPDfFailureCount As Integer
    Private _testPdfSucessCount As Integer
    Private _moveFailedPdfDir As String
    Private _extractImagesDir As String
    Private _saveChangesToPdfDir As String
    Private _sourcePDFDir As String
    Private _animation As clsAnimateImage
    Private _testOptions As clsTestOptions
    Private _reasonTestEnded As String
    Private _image_1 As clsPDFImage
    Private _image_2 As clsPDFImage

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


        _animation = New clsAnimateImage(p_anime, My.Resources._301)

        _testOptions = New clsTestOptions
        _testOptions.Options = My.Settings.testFlags

    End Sub
    Private Sub F_Main_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        _initDataBindings()

        b_stop.Enabled = False
        t_stopAfter.Enabled = c_stopAfter.Checked
        b_changeFailedFolder.Enabled = c_moveFailedPDF.Checked
        b_extractImagesFolder.Enabled = c_extractImagesFolder.Checked
        b_saveChangesToPDFFolder.Enabled = c_saveChangesToPdf.Checked
        r_testFromLocalFolder.Checked = My.Settings.testFromLocalFolder


        _maxLevel = CInt(c_maxDepth.Text)
        _saveDir = My.Settings.saveFolder
        _sourcePDFDir = My.Settings.sourceFolder
        _moveFailedPdfDir = My.Settings.moveFailedPdfFolder
        _extractImagesDir = My.Settings.extractImagesFolder
        _saveChangesToPdfDir = My.Settings.saveChangesToPDFFolder
    End Sub

    Private Sub _initDataBindings()
        t_seed.DataBindings.Clear()
        t_seed.DataBindings.Add(New Binding("Text", My.Settings, "seed"))

        t_stopAfter.DataBindings.Clear()
        t_stopAfter.DataBindings.Add(New Binding("Text", My.Settings, "stopAfterAmount"))

        t_nbrPageForGetImages.DataBindings.Clear()
        t_nbrPageForGetImages.DataBindings.Add(New Binding("Text", My.Settings, "nbrPagesForGetImages"))

        c_maxDepth.DataBindings.Clear()
        c_maxDepth.DataBindings.Add(New Binding("Text", My.Settings, "maxDepth"))

        c_stopAfter.DataBindings.Clear()
        c_stopAfter.DataBindings.Add(New Binding("Checked", My.Settings, "stopAfter"))

        c_moveFailedPDF.DataBindings.Clear()
        c_moveFailedPDF.DataBindings.Add(New Binding("Checked", My.Settings, "moveFailedPDF"))

        c_includeSubFolder.DataBindings.Clear()
        c_includeSubFolder.DataBindings.Add(New Binding("Checked", My.Settings, "includeSubFolder"))

        c_noCaptureDuplicate.DataBindings.Clear()
        c_noCaptureDuplicate.DataBindings.Add(New Binding("Checked", My.Settings, "noCaptureDuplicate"))

        c_maxDegreeOfParallelism.DataBindings.Clear()
        c_maxDegreeOfParallelism.DataBindings.Add(New Binding("Text", My.Settings, "maxDegreeOfParallelism"))

        l_saveFolder.DataBindings.Clear()
        l_saveFolder.DataBindings.Add(New Binding("Text", My.Settings, "saveFolder"))

        l_moveFailedPDFFolder.DataBindings.Clear()
        l_moveFailedPDFFolder.DataBindings.Add(New Binding("Text", My.Settings, "moveFailedPdfFolder"))

        l_extractImagesFolder.DataBindings.Clear()
        l_extractImagesFolder.DataBindings.Add(New Binding("Text", My.Settings, "extractImagesFolder"))

        l_sourceFolder.DataBindings.Clear()
        l_sourceFolder.DataBindings.Add(New Binding("Text", My.Settings, "sourceFolder"))

        l_saveChangesToPDfFolder.DataBindings.Clear()
        l_saveChangesToPDfFolder.DataBindings.Add(New Binding("Text", My.Settings, "saveChangesToPDFFolder"))

        c_testBasicRead.DataBindings.Clear()
        c_testBasicRead.DataBindings.Add(New Binding("Checked", _testOptions, "BasicRead"))

        c_testGetAllPageInformation.DataBindings.Clear()
        c_testGetAllPageInformation.DataBindings.Add(New Binding("Checked", _testOptions, "GetAllPageInformation"))

        c_getAllImages.DataBindings.Clear()
        c_getAllImages.DataBindings.Add(New Binding("Checked", _testOptions, "GetImages"))

        c_extractImagesFolder.DataBindings.Clear()
        c_extractImagesFolder.DataBindings.Add(New Binding("Checked", _testOptions, "ExtractImages"))

        c_createAnnotations.DataBindings.Clear()
        c_createAnnotations.DataBindings.Add(New Binding("Checked", _testOptions, "CreateAnnotations"))

        c_addAnnotations.DataBindings.Clear()
        c_addAnnotations.DataBindings.Add(New Binding("Checked", _testOptions, "AddAnnotations"))

        c_createImages.DataBindings.Clear()
        c_createImages.DataBindings.Add(New Binding("Checked", _testOptions, "CreateImages"))

        c_addImageToPages.DataBindings.Clear()
        c_addImageToPages.DataBindings.Add(New Binding("Checked", _testOptions, "AddImagesToPages"))

        c_erasePageContent.DataBindings.Clear()
        c_erasePageContent.DataBindings.Add(New Binding("Checked", _testOptions, "ErasePageContent"))

        c_rotatePage.DataBindings.Clear()
        c_rotatePage.DataBindings.Add(New Binding("Checked", _testOptions, "RotatePage"))

        c_changeDocumentInformation.DataBindings.Clear()
        c_changeDocumentInformation.DataBindings.Add(New Binding("Checked", _testOptions, "ChangeDocumentInformationAndViewPreferences"))

        c_saveChangesToPdf.DataBindings.Clear()
        c_saveChangesToPdf.DataBindings.Add(New Binding("Checked", _testOptions, "SaveChangesToPDF"))
    End Sub
    Private Sub _startTestBed(MaxLevel As Integer)
        _dataUsage = 0
        _testPDfFailureCount = 0
        _testPdfSucessCount = 0
        _urlViewed = New Dictionary(Of String, clsLink)
        _pdfSaved = New Dictionary(Of String, clsLink)

        _image_1 = New clsPDFImage(Application.StartupPath + "\JpegTestImages\" + "images.jpg")
        _image_2 = New clsPDFImage(Application.StartupPath + "\JpegTestImages\" + "ios.jpg")

        BackgroundWorker1.ReportProgress(0, "Testing Start")

        If r_testFromWeb.Checked Then
            Dim seed As clsLinksFromURL

            _reasonTestEnded = "Test Strategy Completed, all seeds exhausted"

            seed = New clsLinksFromURL(t_seed.Text)
            _getLinks(0, seed)
        Else
            _reasonTestEnded = "Test Strategy Completed, all files in folder tested"
            Dim folder As New DirectoryInfo(_sourcePDFDir)
            If folder.Exists Then
                _testPDFInFolder(folder)
            End If
        End If
        BackgroundWorker1.ReportProgress(0, "Testing Ended")

    End Sub
    Private Sub _testPDFInFolder(folder As DirectoryInfo)
        Dim poptions As New ParallelOptions

        'Dim fichier As FileInfo
        'For Each fichier In folder.GetFiles
        '    If BackgroundWorker1.CancellationPending Then
        '        Exit Sub
        '    End If
        '    If fichier.Extension.ToLower = ".pdf" Then
        '        _testPDF(fichier.FullName)
        '    End If
        'Next

        poptions.MaxDegreeOfParallelism = My.Settings.maxDegreeOfParallelism
        Parallel.ForEach(folder.GetFiles, poptions, Sub(fichier)
                                                        If BackgroundWorker1.CancellationPending Then
                                                            Exit Sub
                                                        End If
                                                        If fichier.Extension.ToLower = ".pdf" Then
                                                            _testPDF(fichier.FullName)
                                                        End If

                                                    End Sub)

        If c_includeSubFolder.Checked Then
            'Parallel.ForEach(folder.GetDirectories, poptions, Sub(dir)
            '                                                      If BackgroundWorker1.CancellationPending Then
            '                                                          Exit Sub
            '                                                      End If
            '                                                      _testPDFInFolder(dir)
            '                                                  End Sub)

            Dim dir As DirectoryInfo
            For Each dir In folder.GetDirectories
                If BackgroundWorker1.CancellationPending Then
                    Exit Sub
                End If
                _testPDFInFolder(dir)
            Next
        End If

    End Sub
    Private Sub _getLinks(Level As Integer, links As clsLinksFromURL)
        Dim poptions As New ParallelOptions
        If Level < _maxLevel Then
            ' Dim link As clsLink

            BackgroundWorker1.ReportProgress(0, "Seed:" + links.Target.ToString)

            ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf _getPDFLinksAndSavePDF), links)

            _dataUsage += links.SizeRead

            poptions.MaxDegreeOfParallelism = My.Settings.maxDegreeOfParallelism
            Parallel.ForEach(links.Links.Values, poptions, Sub(link)
                                                               If BackgroundWorker1.CancellationPending Then
                                                                   Exit Sub
                                                               End If
                                                               If Not _urlViewed.ContainsKey(link.Url) Then
                                                                   _urlViewed.Add(link.Url, link)

                                                                   BackgroundWorker1.ReportProgress(0, "Visiting:" + link.Url)
                                                                   _getLinks(Level + 1, New clsLinksFromURL(link.Url))

                                                               End If

                                                           End Sub)


        End If
    End Sub
    Private Sub _getPDFLinksAndSavePDF(links As clsLinksFromURL)
        Dim pdfLink As clsPDFFromLinks

        pdfLink = New clsPDFFromLinks(links.Links)
        _savePDF(pdfLink.Links)
    End Sub

    Private Sub _updateMetrics()
        l_nbrUrlRead.Text = _urlViewed.Count
        l_pdfSaved.Text = _pdfSaved.Count
        l_dataUsage.Text = Math.Round(_dataUsage / _mbSize, 2).ToString + " Mb"
        l_testFailedCount.Text = _testPDfFailureCount.ToString
        l_pdfTestSuccessCount.Text = _testPdfSucessCount.ToString

        If _testPDfFailureCount > 0 And l_testFailedCount.ForeColor <> Color.Red Then
            l_testFailedCount.ForeColor = Color.Red
            l_testFailedCount.Font = New Font(l_testFailedCount.Font, FontStyle.Bold)
        End If

        If _testPdfSucessCount > 0 And l_pdfTestSuccessCount.ForeColor <> Color.Green Then
            l_pdfTestSuccessCount.ForeColor = Color.Green
            l_pdfTestSuccessCount.Font = New Font(l_pdfSaved.Font, FontStyle.Bold)
        End If

        If c_stopAfter.Checked Then
            If _dataUsage >= (CLng(t_stopAfter.Text) * _mbSize) Then
                _animation.StopAnimation()
                F_WaitOperation.Show()
                _reasonTestEnded = "Testing stopped, maximum data usage reached"
                BackgroundWorker1.CancelAsync()
            End If
        End If
    End Sub
    Private Sub _writeLog(s As String, logField As TextBox)
        Dim output As String
        output = String.Format("[{0}] : {1}", Now.ToLongDateString + "|" + Now.ToLongTimeString, s)
        logField.AppendText(output + ControlChars.CrLf)
    End Sub
    Private Sub _savePDF(links As Dictionary(Of String, clsLink))
        Dim fullPath As String
        Dim f As FileInfo
        Dim link As clsLink
        Dim u As Uri
        Dim dir As DirectoryInfo

        dir = New DirectoryInfo(_saveDir)
        If dir.Exists Then
            For Each link In links.Values
                If BackgroundWorker1.CancellationPending Then
                    Exit For
                End If
                Try
                    If Not _pdfSaved.ContainsKey(link.Url) Then
                        u = New Uri(link.Url)
                        fullPath = dir.FullName + "\" + link.Name
                        If My.Settings.noCaptureDuplicate Then
                            f = New FileInfo(fullPath)
                            If Not f.Exists Then
                                _savePDF(link, fullPath)
                                BackgroundWorker1.ReportProgress(0, " -- PDF:" + link.Url)
                            End If
                        Else
                            _savePDF(link, fullPath)
                            BackgroundWorker1.ReportProgress(0, " -- PDF:" + link.Url)
                        End If

                    End If
                Catch ex As Exception
                End Try
            Next
        Else
            Throw New Exception("Save Directory does not exist")
        End If
    End Sub
    Private Sub _savePDF(link As clsLink, pathToSave As String)
        Dim wc As WebClient
        Dim f As FileInfo

        Try
            wc = New WebClient
            wc.DownloadFile(link.Url, pathToSave)
            f = New FileInfo(pathToSave)
            _dataUsage += f.Length
            _pdfSaved.Add(link.Url, link)
            _testPDF(pathToSave)

        Catch ex As Exception

        End Try
    End Sub
    Private Sub _testPDF(pdfPath As String)
        BackgroundWorker1.ReportProgress(0, " -- Testing:" + pdfPath)

        Dim test As New clsTestPDF(pdfPath, _testOptions)

        test.TestImageList.Add(_image_1)
        test.TestImageList.Add(_image_2)
        test.SaveChangesToPdfFolder = _saveChangesToPdfDir

        test.PerformTest()

        If Not test.Success Then
            _testPDfFailureCount += 1
            If c_moveFailedPDF.Checked Then
                Dim f As New FileInfo(pdfPath)
                Dim dest As New FileInfo(_moveFailedPdfDir + "\" + f.Name)
                If Not dest.Exists Then
                    f.MoveTo(dest.FullName)
                End If
            End If
            BackgroundWorker1.ReportProgress(1, pdfPath)
            BackgroundWorker1.ReportProgress(1, " -- " + test.TestStage)
            BackgroundWorker1.ReportProgress(1, " -- " + test.LastException.Message)
        Else
            _testPdfSucessCount += 1
        End If

    End Sub
    Private Sub b_start_Click(sender As Object, e As EventArgs) Handles b_start.Click
        If _validateAllFolders() Then
            b_start.Enabled = False
            b_stop.Enabled = True
            My.Settings.Save()
            t_log.Clear()
            t_PdfTestFailedLog.Clear()
            BackgroundWorker1.RunWorkerAsync()
            _animation.StartAnimation()
        End If
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        _startTestBed(_maxLevel)
        e.Cancel = True
    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        Select Case e.ProgressPercentage
            Case 1
                _writeLog(e.UserState, t_PdfTestFailedLog)
            Case Else
                _writeLog(e.UserState, t_log)
        End Select
        _updateMetrics()
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        b_stop.Enabled = False
        b_start.Enabled = True
        F_WaitOperation.Hide()
        _animation.StopAnimation()
        _writeLog(_reasonTestEnded, t_log)
        MsgBox(_reasonTestEnded, MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "")
    End Sub

    Private Sub b_stop_Click(sender As Object, e As EventArgs) Handles b_stop.Click
        _reasonTestEnded = "Testing stopped by the user"
        b_stop.Enabled = False
        _animation.StopAnimation()
        F_WaitOperation.Show(Me)
        BackgroundWorker1.CancelAsync()
    End Sub
    Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        BackgroundWorker1.CancelAsync()
        My.Settings.testFlags = _testOptions.Options
        My.Settings.testFromLocalFolder = r_testFromLocalFolder.Checked
        My.Settings.Save()
    End Sub

    Private Sub c_maxDepth_SelectedIndexChanged(sender As Object, e As EventArgs) Handles c_maxDepth.SelectedIndexChanged
        _maxLevel = CInt(c_maxDepth.Text)
    End Sub
    Private Sub c_moveFailedPDF_CheckedChanged(sender As Object, e As EventArgs) Handles c_moveFailedPDF.CheckedChanged
        b_changeFailedFolder.Enabled = c_moveFailedPDF.Checked
    End Sub
    Private Sub c_getAllImages_CheckedChanged(sender As Object, e As EventArgs) Handles c_getAllImages.CheckedChanged
        t_nbrPageForGetImages.Enabled = c_getAllImages.Checked
        c_extractImagesFolder.Enabled = c_getAllImages.Checked
        b_extractImagesFolder.Enabled = c_getAllImages.Checked
    End Sub

    Private Sub c_stopAfter_CheckedChanged(sender As Object, e As EventArgs) Handles c_stopAfter.CheckedChanged, c_noCaptureDuplicate.CheckedChanged
        t_stopAfter.Enabled = c_stopAfter.Checked
    End Sub
    Private Sub c_extractImagesFolder_CheckedChanged(sender As Object, e As EventArgs) Handles c_extractImagesFolder.CheckedChanged
        b_extractImagesFolder.Enabled = c_extractImagesFolder.Checked
    End Sub
    Private Sub c_saveChangesToPdf_CheckedChanged(sender As Object, e As EventArgs) Handles c_saveChangesToPdf.CheckedChanged
        b_saveChangesToPDFFolder.Enabled = c_saveChangesToPdf.Checked
    End Sub
    Private Sub r_testFromLocalFolder_CheckedChanged(sender As Object, e As EventArgs) Handles r_testFromLocalFolder.CheckedChanged
        p_testFromLocalFolder.Enabled = r_testFromLocalFolder.Checked
        p_testFromTheWeb.Enabled = Not r_testFromLocalFolder.Checked
    End Sub
    Private Sub r_testFromWeb_CheckedChanged(sender As Object, e As EventArgs) Handles r_testFromWeb.CheckedChanged
        p_testFromTheWeb.Enabled = r_testFromWeb.Checked
        p_testFromLocalFolder.Enabled = Not r_testFromWeb.Checked
    End Sub
    Private Sub b_extractImagesFolder_Click(sender As Object, e As EventArgs) Handles b_extractImagesFolder.Click
        _changeFolder(_extractImagesDir, l_extractImagesFolder, My.Settings.extractImagesFolder)
    End Sub
    Private Sub b_changeFailedFolder_Click(sender As Object, e As EventArgs) Handles b_changeFailedFolder.Click
        _changeFolder(_moveFailedPdfDir, l_moveFailedPDFFolder, My.Settings.moveFailedPdfFolder)
    End Sub
    Private Sub b_changeFolder_Click(sender As Object, e As EventArgs) Handles b_changeFolder.Click
        _changeFolder(_saveDir, l_saveFolder, My.Settings.saveFolder)
    End Sub
    Private Sub b_folderSource_Click(sender As Object, e As EventArgs) Handles b_folderSource.Click
        _changeFolder(_sourcePDFDir, l_sourceFolder, My.Settings.sourceFolder)
    End Sub
    Private Sub b_saveChangesToPDF_Click(sender As Object, e As EventArgs) Handles b_saveChangesToPDFFolder.Click
        _changeFolder(_saveChangesToPdfDir, l_saveChangesToPDfFolder, My.Settings.saveChangesToPDFFolder)
    End Sub
    Private Sub _changeFolder(_folderPath As String, l As Label, ByRef pref As String)
        Dim d As New FolderBrowserDialog
        Dim res As DialogResult

        d.SelectedPath = _folderPath
        res = d.ShowDialog
        If res = Windows.Forms.DialogResult.OK Then
            _folderPath = d.SelectedPath
            l.Text = _folderPath
            pref = _folderPath
        End If

    End Sub

    Private Sub t_seed_Validating(sender As Object, e As CancelEventArgs) Handles t_seed.Validating
        Dim pattern As String = "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$"
        Dim reg As New Regex(pattern, RegexOptions.IgnoreCase)
        If Not reg.IsMatch(t_seed.Text) Then
            e.Cancel = True
            MsgBox("You have entered an invalid URL", MsgBoxStyle.Exclamation, "")
            t_seed.Text = My.Settings.seed
            t_seed.SelectAll()
        End If
    End Sub

    Private Sub c_maxDepth_Validating(sender As Object, e As CancelEventArgs) Handles c_maxDepth.Validating
        Dim depth As Integer
        Try
            depth = CInt(c_maxDepth.Text)
            If depth > 10 Then
                e.Cancel = True
            End If
        Catch ex As Exception
            e.Cancel = True
        End Try
        If e.Cancel Then
            MsgBox("Maximum depth must be 10 or lower", MsgBoxStyle.Exclamation, "")
            c_maxDepth.Text = My.Settings.maxDepth
            c_maxDepth.SelectAll()
        End If
    End Sub

    Private Function _validateFolder(folderPath As String)
        Dim folder As New DirectoryInfo(folderPath)
        _validateFolder = folder.Exists
    End Function
    Private Function _validateAllFolders() As Boolean
        _validateAllFolders = False

        If r_testFromWeb.Checked Then
            _validateAllFolders = _validateFolder(_saveDir)
            If Not _validateAllFolders Then
                MsgBox("Capture PDF Folder (" + _saveDir + ") is invalid", MsgBoxStyle.Exclamation, "")
                Exit Function
            End If
        Else
            _validateAllFolders = _validateFolder(_sourcePDFDir)
            If Not _validateAllFolders Then
                MsgBox("PDF Source Folder (" + _sourcePDFDir + ") is invalid", MsgBoxStyle.Exclamation, "")
                Exit Function
            End If
        End If

        If My.Settings.moveFailedPDF Then
            _validateAllFolders = _validateFolder(_moveFailedPdfDir)
            If Not _validateAllFolders Then
                MsgBox("Move failed folder (" + _moveFailedPdfDir + ") is invalid", MsgBoxStyle.Exclamation, "")
                Exit Function
            End If
        End If

        If _testOptions.ExtractImages Then
            _validateAllFolders = _validateFolder(_extractImagesDir)
            If Not _validateAllFolders Then
                MsgBox("Extract image folder (" + _extractImagesDir + ") is invalid", MsgBoxStyle.Exclamation, "")
                Exit Function
            End If
        End If
        If _testOptions.SaveChangesToPDF Then
            _validateAllFolders = _validateFolder(_saveChangesToPdfDir)
            If Not _validateAllFolders Then
                MsgBox("Save changes to PDF folder (" + _saveChangesToPdfDir + ") is invalid", MsgBoxStyle.Exclamation, "")
                Exit Function
            End If
        End If
    End Function

    Private Sub t_stopAfter_Validating(sender As Object, e As CancelEventArgs) Handles t_stopAfter.Validating
        If My.Settings.stopAfter Then
            Dim max As Long
            Try
                max = CLng(t_stopAfter.Text)
            Catch ex As Exception
                e.Cancel = True
            End Try
            If e.Cancel Then
                MsgBox("Maximum Data usage is invalid", MsgBoxStyle.Exclamation, "")
                t_stopAfter.Text = My.Settings.stopAfterAmount
                t_stopAfter.SelectAll()
            End If
        End If

    End Sub

    Private Sub c_maxDegreeOfParallelism_Validating(sender As Object, e As CancelEventArgs) Handles c_maxDegreeOfParallelism.Validating
        Dim max As Integer
        Try
            max = CInt(c_maxDegreeOfParallelism.Text)
            If max > 20 Or max = 0 Or max < -1 Then
                e.Cancel = True
            End If
        Catch ex As Exception
            e.Cancel = True
        End Try
        If e.Cancel Then
            MsgBox("Maximum degree of parallelism must be between 1 and 20", MsgBoxStyle.Exclamation, "")
            c_maxDegreeOfParallelism.Text = My.Settings.maxDegreeOfParallelism
            c_maxDegreeOfParallelism.SelectAll()
        End If
    End Sub

    Private Sub t_nbrPageForGetImages_Validating(sender As Object, e As CancelEventArgs) Handles t_nbrPageForGetImages.Validating
        If _testOptions.GetImages Then
            Dim nbr As Integer
            Try
                nbr = CInt(t_nbrPageForGetImages.Text)
            Catch ex As Exception
                e.Cancel = True
            End Try
            If e.Cancel Then
                MsgBox("Number of pages is invalid", MsgBoxStyle.Exclamation, "")
                t_nbrPageForGetImages.Text = My.Settings.nbrPagesForGetImages
                t_nbrPageForGetImages.SelectAll()
            End If
        End If

    End Sub

End Class